<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>


    <style>
        body{
            padding: 0;
            margin: 0;
            background-color: antiquewhite;
           

        }

        .box {
            overflow-x: scroll;
            overflow-y: hidden;
            display: flex;
            height: 100vh;
            width: 100vw;

            /* 设置滚动吸附类型 
              y:y轴，还可以设置x
              mandatory: 强制吸附
              proximity: 接近吸附,允许中间状态
            */
            scroll-snap-type: x proximity;
            scroll-behavior: smooth;
        }

        .c{
            width: 100vw;
            height: 100vh;
            background-color: blueviolet;
            flex-basis: 100vw;
            flex-shrink: 0;

            /* 
            start:吸附左边
            end:吸附右边
            center:吸附中间
             */
            scroll-snap-align: center;

            /* 每个元素都停留，不然可能一下子滚动多个元素 */
            scroll-snap-stop: always;

        }
        .c:nth-child(2n) {
            background-color: aquamarine;
        }
       
    </style>
</head>
<body>

    <section class="box">
        <div class="c"></div>
        <div class="c"></div>
        <div class="c"></div>
        <div class="c"></div>
        <div class="c"></div>
    </section>
    
</body>
</html>